<template>
	<view>
		<form @submit="formSubmit" @reset="formReset" class="uni-form">
			<view class="section">
				<input type="password" placeholder="原密码" v-model="oldPas"/>
			</view>
			<view class="section">
				<input type="password" placeholder="新密码" v-model="newPas"/>
			</view>
			<view class="section">
				<input type="password" placeholder="确认新密码" v-model="again"/>
			</view>
			<view class="btn-area">
				<button type="primary" @click="submit">确认</button>
			</view>
		</form>
	</view>
</template>

<script>
	let common = require('../../common/common.js')
	export default{
		data(){
			return{
				oldPas:'',
				newPas:'',
				again:''
			}
		},
		methods:{
			submit(){
				if(!this.oldPas){
					uni.showToast({
						icon: 'none',
						title: '请输入您要修改的密码'
					});
					return
				}
				if(!common.pasVertify(this.oldPas).type || !common.pasVertify(this.newPas).type || !common.pasVertify(this.again).type){
					uni.showToast({
						icon: 'none',
						title: '密码由数字或密码或-_组成'
					});
					return
				}
				if(this.oldPas === this.newPas){
					uni.showToast({
						icon: 'none',
						title: '新密码不能与旧密码相同'
					});
					return
				}
				if(this.again != this.newPas){
					uni.showToast({
						icon: 'none',
						title: '两次密码不一致'
					});
					return
				}
				uni.request({
					url: this.$BaseUrl + '/user/editPassword',
					method:'POST',
					data:{
						id: uni.getStorageSync('userInfo').id,
						oldPassword: this.oldPas,
						newPassword: this.newPas
					},
					success:(res)=>{
						if(res.data.code == 0){
							uni.showToast({
								icon:'none',
								title:`${res.data.msg},返回登录`
							});
							setTimeout(()=>{
								uni.navigateBack({
									delta: 2
								});
							},2000)
						}
					}
				})
			}
		}
	}
</script>

<style>
	.uni-form input{
		width:91.47%;
		height: 100upx;
		margin: auto;
		font-size: 28upx;
		line-height: 100upx;
		border-bottom:1px solid #ddd ;
	}
	.btn-area{
		width:91.47%;
		margin:90upx auto;
		background-color: #02A8F4;
	}
</style>